package com.liveneo.adapter.webservice.server.claim;

import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.liveneo.adapter.mobile.model.dto.VsRequestHeadDto;
import com.liveneo.adapter.mobile.model.dto.VsResponseHeadDto;
import com.liveneo.adapter.mobile.util.SysConst;
import com.liveneo.adapter.mobile.util.UserException;
import com.liveneo.adapter.webservice.server.claim.model.Claim2VsResponse;
import com.liveneo.adapter.webservice.server.claim.model.dto.EvaluateInfoResponseDto;
import com.liveneo.system.base.utils.MD5;

public class ClaimHeadClient {
    /**
     * 请求交易头信息
     * @param operation
     * @return
     */
    public static VsRequestHeadDto setVsRequestHeadDto(String operation) {
        VsRequestHeadDto vsRequestHeadDto = new VsRequestHeadDto();
        vsRequestHeadDto.setOperation(operation);
        vsRequestHeadDto.setServiceCode("VideoSurveyService");
        vsRequestHeadDto.setServiceName("车险视频查勘定损系统");
        vsRequestHeadDto.setClientCode("handkoo");
        vsRequestHeadDto.setClientName("handkoo");
        vsRequestHeadDto.setPassword(MD5.GetMD5Code("QO73*3%mms"));
        vsRequestHeadDto.setServerCode("002");
        vsRequestHeadDto.setRequestID(operation);
        vsRequestHeadDto.setUsrSignature("");
        vsRequestHeadDto.setUserCode("handkoo");
        vsRequestHeadDto.setUserName("handkoo");
        return vsRequestHeadDto;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void printResponse(Claim2VsResponse Response, String name) {
        if (Response != null) {
            VsResponseHeadDto vsResponseHeadDto = Response.getVsResponseHeadDto();
            if (vsResponseHeadDto != null) {
                System.out.println("返回数据：");
                System.out.println("结果代码=" + vsResponseHeadDto.getResultCode());
                System.out.println("服务代码=" + vsResponseHeadDto.getServiceCode());
                System.out.println("服务名称=" + vsResponseHeadDto.getServiceName());
                System.out.println("操作名称=" + vsResponseHeadDto.getOperation());
                System.out.println("请求ID=" + vsResponseHeadDto.getRequestID());
                System.out.println("错误信息=" + vsResponseHeadDto.getErrorMessage());
            }
            List<GcEvaluateFit> list_fit;
            // Object list_acc;
            List<GcEvaluateAccessory> list_acc;
            try {
                if (StringUtils.equals(name, SysConst.getProperty("CLAIM_FINDEVALUATEINFO"))) {
                    EvaluateInfoResponseDto evaluateInfoResponseDto = Response.getDoWithEvaluateDocInfoResponseDto();
                    EstimateInfo estimateInfo = evaluateInfoResponseDto.getEstimateInfo();
                    if (("000".equals(vsResponseHeadDto.getResultCode())) && (estimateInfo != null)) {
                        System.out.println("====估损单====");
                        System.out.println("报案号=" + estimateInfo.getRegistNo());
                        System.out.println("被保险人=" + estimateInfo.getInsurantName());
                        System.out.println("标的车牌号=" + estimateInfo.getLicenseNo());
                        System.out.println("标的车VIN（车架号）=" + estimateInfo.getFrameNo());
                        System.out.println("出险时驾驶员=" + estimateInfo.getDriverName());
                        System.out.println("出险日期=" + estimateInfo.getDamageDate());
                        System.out.println("定损车牌号=" + estimateInfo.getLossLicenseNo());
                        System.out.println("是否标的=" + estimateInfo.getIfObject());
                        System.out.println("定损金额合计=" + estimateInfo.getLossAmountTotal());
                        list_fit = evaluateInfoResponseDto.getGcEvaluateFit();
                        System.out.println("换件信息(" + list_fit.size() + ")：");
                        System.out.println("零件名称----零件数量----单价");
                        for (GcEvaluateFit fit : list_fit) {
                            System.out.println(fit.getObjectName() + "----" + fit.getLossNumber() + "----" + fit.getLossPrice());
                        }
                        System.out.println("总价：" + estimateInfo.getFitSumAmount() + "(" + estimateInfo.getFitSumAmountStr() + ")");
                        List<GcEvaluateRepair> list_repair = evaluateInfoResponseDto.getGcEvaluateRepair();
                        if (!list_repair.isEmpty()) {
                            System.out.println("修理信息(" + list_repair.size() + ")：");
                            System.out.println("修理件名称----工时费");
                            for (GcEvaluateRepair repair : list_repair) {
                                System.out.println(repair.getObjectName() + "----" + repair.getLossAmount());
                            }
                            System.out.println("总价：" + estimateInfo.getRepairSumAmount() + "(" + estimateInfo.getRepairSumAmountStr() + ")");
                        }
                        list_acc = evaluateInfoResponseDto.getGcEvaluateAccessory();
                        if (!((List) list_acc).isEmpty()) {
                            System.out.println("辅料信息(" + ((List) list_acc).size() + ")：");
                            System.out.println("辅料项目名称----数量----单价----合计");
                            for (GcEvaluateAccessory acc : list_acc) {
                                System.out.println(acc.getAccessoryName() + "----" + acc.getLossNumber() + "----" + acc.getLossPrice() + "----"
                                        + acc.getLossAmount());
                            }
                            System.out.println("总价：" + estimateInfo.getAccessorySumAmount() + "(" + estimateInfo.getAccessorySumAmountStr() + ")");
                        }
                        System.out.println();
                        System.out.println(estimateInfo.getLossAmountTotal());
                        System.out.println(estimateInfo.getLossAmountTotalStr());
                    }
                } else if (StringUtils.equals(name, "upoadImage")) {
                    List<ErrorImages> images = Response.getErrorImages();
                    if ((images != null) && (images.size() > 0)) {
                        for (ErrorImages e : images) {
                            System.out.println(e.registNo + "---" + e.imgName);
                        }
                    }
                } else if (StringUtils.equals(name, "findCaseInfo")) {
                    CaseInfo caseinfo = Response.getCaseinfo();
                    if (caseinfo != null) {
                        StringBuffer sb = new StringBuffer();
                        sb.append("报案号：" + caseinfo.getRegistNo() + "\n");
                        sb.append("出险地点：" + caseinfo.getDamagePlace() + "\n");
                        sb.append("出险时间：" + caseinfo.getDamageDate() + "\n");
                        sb.append("车牌号：" + caseinfo.getLicenseNo());
                        List list = caseinfo.getPolicyLst();
                        sb.append("保单信息：\n");
                        for (list_acc = (List<GcEvaluateAccessory>) list.iterator(); ((Iterator) list_acc).hasNext();) {
                            PolicyInfo p = (PolicyInfo) ((Iterator) list_acc).next();
                            sb.append("保单号:" + p.getPolicyNo() + ",险种:" + p.getSpeciesName() + ",险类:" + p.getCategoryName() + ",投保人:" + p.getAppliName()
                                    + ",被保险人:" + p.getInsuredName() + "\n");
                        }
                        System.out.println(sb.toString());
                    }
                }
            } catch (UserException e) {
                e.printStackTrace();
            }
        }
    }
}
